package com.example.controller;

import com.example.common.Result;
import com.example.dto.*;
import com.example.service.SignInService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/signIn")
@RequiredArgsConstructor
public class SignInController {
    private final SignInService signInService;

    @PostMapping("/create")
    public Result createSignIn(@RequestBody SignInCreateDTO dto) {
        return Result.success(signInService.createSignIn(dto));
    }

    @PostMapping("/record")
    public Result recordSignIn(@RequestBody SignInRecordDTO dto,
                               @RequestParam Integer studentId) { // 直接传 studentId
        signInService.recordSignIn(dto, studentId);
        return Result.success();
    }

    @GetMapping("/active")
    public Result getActiveSignIn(@RequestParam Integer courseId,
                                  @RequestParam Integer studentId) {
        return Result.success(signInService.getActiveSignIn(courseId, studentId));
    }
    @PostMapping("/calculateDistance")
    public Result calculateDistance(@RequestBody DistanceCalculateDTO dto) {
        double distance = signInService.calculateDistance(
                dto.getLat1(), dto.getLng1(), dto.getLat2(), dto.getLng2());
        DistanceDTO result = new DistanceDTO();
        result.setDistance(distance);
        return Result.success(result);
    }

    @GetMapping("/stats")
    public Result getSignInStats(@RequestParam Integer courseId) {
        return Result.success(signInService.getSignInStats(courseId));
    }

    @GetMapping("/records")
    public Result getSignInRecords(@RequestParam Integer courseId) {
        return Result.success(signInService.getSignInRecords(courseId));
    }
}